﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QLPKWeb.BussinessDelegate.Base;
using QLPKWeb.Models.FormBean.PhanQuyen;
using DONGACS.Common;
using DONGACS.DTO;
using DONGACS.SERVICE;
using DONGACS.Domain;

namespace QLPKWeb.BussinessDelegate.PhanQuyen
{
    public class DepartmentsServiceDelegate : BaseServiceDelegate<DepartmentsDto, Departments>
    {
        DepartmentsService DepartmentsService = new DepartmentsService();

        //public DepartmentsService DepartmentsService
        //{
        //    get
        //    {
        //        return (DepartmentsService)this.BaseService;
        //    }
        //}

        //public IList<DepartmentsDto> GetAllDepartments()
        //{
        //    return DepartmentsService.GetAllDepartments();
        //}

        public DepartmentsDto GetDepartmentsById(string id)
        {
            return DepartmentsService.GetDepartmentsById(id);
        }

        public DepartmentsDto BuildNewDepartments(DepartmentsForm form)
        {
            DepartmentsDto newDepartment = new DepartmentsDto();
            newDepartment.DepartmentName = form.DepartmentName;
            newDepartment.DepartmentDesc = form.DepartmentDesc;
            newDepartment.IdChief = form.IdChief;
            newDepartment.CreateDate = DateTime.Now;
            newDepartment.UpdateDate = DateTime.Now;
            newDepartment.CreateBy = Convert.ToInt32(HttpContext.Current.Session["USERID"]);
            newDepartment.UpdateBy = Convert.ToInt32(HttpContext.Current.Session["USERID"]);
            newDepartment.IsDelete = false;

            return newDepartment;
        }

        public DepartmentsDto BuildEditDepartments(DepartmentsForm form)
        {
            DepartmentsDto newDepartment = this.DepartmentsService.GetDepartmentsById(form.ID.ToString());
            newDepartment.DepartmentName = form.DepartmentName;
            newDepartment.DepartmentDesc = form.DepartmentDesc;
            newDepartment.IdChief = form.IdChief;
            //newDepartment.CreateDate = DateTime.Now;
            newDepartment.UpdateDate = DateTime.Now;
            //newDepartment.CreateBy = SessionDetail.USERID;
            newDepartment.UpdateBy = Convert.ToInt32(HttpContext.Current.Session["USERID"]);
            //newDepartment.IsDelete = false;

            return newDepartment;
        }

        public bool AddNewDepartments(DepartmentsDto departmentsDto)
        {
            return this.DepartmentsService.AddNewDepartments(departmentsDto);
        }

        public bool AddNewDepartments(DepartmentsDto departmentsDto, ref int idReturn)
        {
            return this.DepartmentsService.AddNewDepartments(departmentsDto, ref idReturn);
        }

        public bool Update(DepartmentsDto departmentsDto)
        {
            return this.DepartmentsService.Update(departmentsDto);
        }

        public bool ShiftDelete(string departmentsId)
        {
            return this.DepartmentsService.ShiftDelete(departmentsId);
        }

        public bool Delete(string departmentsId)
        {
            return this.DepartmentsService.Delete(departmentsId);
        }

        public DepartmentsDto GetDepartmentsByName(string departmentName)
        {
            return this.DepartmentsService.GetDepartmentsByName(departmentName);
        }


        public SelectList BuildDepartmentSelectList()
        {
            IList<DepartmentsDto> list;
            
            list = DepartmentsService.GetAllEntities();//test

            IList<object> selectList = new List<object> { new { value = 0, Text = "[-- Choose Department --]" } };

            foreach (var dto in list)
            {
                selectList.Add(new { value = dto.ID, Text = dto.DepartmentName });
            }

            return new SelectList(selectList, "Value", "Text");
        }
    }
}
